package com.xinsoft.controller.basic;


import com.alibaba.fastjson.JSONObject;
import com.xinsoft.common.Response;
import com.xinsoft.common.WeChatParamesUtil;
import com.xinsoft.utils.WeChatUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

/**
 * @ClassName SysWeChartController
 * @Description 微信控制层
 * @Author lijie
 * @Date 2023/5/11 17:08 星期四
 * @Version 1.0
 */
@RestController
@RequestMapping("/system/weChart")
@Api(value = "SysWeChartController", tags = {"微信控制层"})
public class SysWeChartController {

    /**
     * @Author Li9527
     * @Description 获取详情
     * @Date 2023/5/12 9:20
     * @params   id
     * @return com.xinsoft.common.Response<?>
     **/
    @ApiOperation("获取详情")
    @GetMapping("/getAccessToken")
    public Response<?> getAccessToken() throws NoSuchAlgorithmException, IOException, NoSuchProviderException, KeyManagementException {
        // 1.获取access_token:根据企业id和应用密钥获取access_token,并拼接请求url
        String accessToken = WeChatUtil.getAccessToken(WeChatParamesUtil.corpId, WeChatParamesUtil.corpsecret).getToken();
        return Response.succeed(accessToken);
    }


    /**
     * 获取企业号的jsApiTicket
     * @param accessToken
     * @return
     * @throws IOException
     */
    @GetMapping("/getJsapiTicket")
    public static  Response<?>  getJsapiTicket(String accessToken) throws IOException {
        // 1.获取access_token:根据企业id和应用密钥获取access_token,并拼接请求url
        JSONObject jsonObject = WeChatUtil.getJsapiTicket(accessToken);
        return Response.succeed(jsonObject);
    }

}
